from math import log


class AdamicAdar:

    def __init__(self, vertex1, vertex2, vertices):
        self.vertex = (vertex1.vertex, vertex2.vertex)
        self.value = 0
        self.calc_value(vertex1, vertex2, vertices)

    def __lt__(self, other):
        return self.value < other.value

    def calc_value(self, vertex1, vertex2, vertices):
        for vertex in vertex1.inverse_sampling:
            if vertex in vertex2.inverse_sampling:
                vertex_obj = vertices[vertex]
                if vertex_obj.sketch.est == 1:
                    self.add_value(vertex_obj.sketch)

    def add_value(self, sampling):
        self.value += 1/(log(sampling.get_count()))
